package com.LJH.WebTask4.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class LoginController {
    @Resource
    HttpServletRequest req;

    @GetMapping("/login")
    public String loginForm() {
        return "Login";
    }

    @PostMapping("/login")
    public String login(@RequestParam String userName, @RequestParam String password) throws IOException {
        if (userName.equals("admin") && password.equals("123456")) {
            HttpSession session = req.getSession();
            session.setAttribute("status", "success");
            return "redirect:/booklist";
        }
        else {
            return "redirect:/login";
        }
    }
}
